import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/home/Index.vue'
import Login from '../views/login/Login.vue'
import Register from '../views/register/Register.vue'
import Index from '../views/home/Index.vue'
import My from '../views/my/My.vue'
import Order from '../views/order/Order.vue'
import Detail from '../views/detail/Detail.vue'
import Count from '../views/detail/components/Count.vue'
// import ShopCart from '../views/shopCart/ShopCart.vue'
// import ShopCartList from '../views/shopcart/ShopCartList.vue'
import store from '../store/index.js';





const routes = [{
        path: '/order',
        name: 'order',
        component: Order
    },

    {
        path: '/my',
        name: 'my',
        component: My,
        beforeEnter(to, from, next) {
            if (sessionStorage.getItem("token") != undefined) {
                console.log(1)
                next();
            } else {
                console.log(to.fullPath);
                router.push("/login?redirect=" + to.fullPath);
            }
        },
    },


    {
        path: '/login',
        name: 'login',
        component: Login
    },
    {

        path: '/',
        name: 'home',
        component: Home
    },
    {
        path: '/register',
        name: 'register',
        component: Register
    },

    {
        path: '/index',
        name: 'index',
        component: Index
    },
    {
        path: '/detail',
        name: 'detail',
        component: Detail
    },
    {
        path: '/count',
        name: 'count',
        component: Count,
    },
    {
        path: '/manageaddress',
        name: 'ManageAddress',
        component: () =>
            import ('../views/my/Address/ManageAddress.vue')
    },
    {
        path: '/editaddress',
        name: 'EditAddress',
        component: () =>
            import ('../views/my/Address/EditAddress.vue')
    },
    {
        path: '/newaddress',
        name: 'NewAddress',
        component: () =>
            import ('../views/my/Address/NewAddress.vue')
    },
    // {
    //     path: '/shopCart',
    //     name: 'shopCart',
    //     component: ShopCart,
    //     beforeEnter(to, from, next) {
    //         if (sessionStorage.getItem('token') != undefined) {
    //             next();
    //         } else {
    //             console.log(to.fullPath);

    //             router.push('/login?redirect=' + to.fullPath);
    //         }
    //     }
    // },
    {
        path: '/shopcart',
        name: 'shopCart',
        component: () =>
            import ('../views/shopCart'),
        beforeEnter(to, from, next) {
            if (sessionStorage.getItem('token') != undefined) {
                next();
            } else {
                router.push('/login?redirect=' + to.fullPath);
            }
        }
    },
    // {
    //     path: '/shopcartlist',
    //     name: 'shopcartlist',
    //     component: ShopCartList,
    // },
    // {
    //     path: '/about',
    //     name: 'about',
    //     // route level code-splitting
    //     // this generates a separate chunk (about.[hash].js) for this route
    //     // which is lazy-loaded when the route is visited.
    //     component: () =>
    //         import ( /* webpackChunkName: "about" */ '../views/AboutView.vue')
    // }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})
export default router